import { defineStore } from "pinia";

import {
  postCourseCategory,
  postCourseTime,
  postCourseAddress,
  postCourseTag,
} from "~/api/aviation";

const postCourseCategoryFunc = new Promise(async (resolve, reject) => {
  let res = await postCourseCategory();
  if (res.code === 200) {
    let obj = {
      label: "课程类型",
      list: res.data,
    };
    resolve(obj);
  }
});
const postCourseTimeFunc = new Promise(async (resolve, reject) => {
  let res = await postCourseTime();
  if (res.code === 200) {
    let obj = {
      label: "开课时间",
      list: res.data,
    };
    resolve(obj);
  }
});
const postCourseAddressFunc = new Promise(async (resolve, reject) => {
  let res = await postCourseAddress();
  if (res.code === 200) {
    let obj = {
      label: "开课地点",
      list: res.data,
    };
    resolve(obj);
  }
});
const postCourseStatusFunc = new Promise((resolve, reject) => {
  let obj = {
    label: "报名状态",
    list: [{ id: 1, title: "报名中" }],
  };
  resolve(obj);
});
const postCourseTagFunc = new Promise(async (resolve, reject) => {
  let res = await postCourseTag();
  if (res.code === 200) {
    let obj = {
      label: "课程标签",
      list: res.data,
    };
    resolve(obj);
  }
});
const postSearchTagFunc = new Promise(async (resolve, reject) => {
  let obj = {
    label: "关键词",
    type: "input",
    value: "",
  };
  resolve(obj);
});

export const useAviationFilterData = async () => {
  let res = await Promise.all([
    // postCourseCategoryFunc,
    postCourseTimeFunc,
    postCourseAddressFunc,
    postCourseStatusFunc,
    postCourseTagFunc,
    postSearchTagFunc,
  ]);

  return res;
};

/**
 * 获取课程数据
 */
import { postCouseList } from "~/api/aviation";

export const useAviationCourseData = async () => {
  let res = await postCouseList();
  if (res.code === 200) {
    return res.data;
  }
  return [];
};
